﻿using Core.Users;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Infrastructure.Managers
{
    public class UserManager : BaseManager
    {
        public virtual void RegisterUser(string userName, string password, string email, string lang, bool isRequireConfirmationToken)
        {
            //code in subclass
        }

        public virtual IEnumerable<UserProfile> GetAllUsers()
        {
            var users = _dbContext.Get<UserProfile>();
            return users;
        }

        public virtual string[] GetAllRoles()
        {
            //code in subclass
            return null;
        }

        public virtual bool IsUserInRole(string userLogin, string roleName)
        {
            //code in subclass
            return false;
        }

        public virtual void AddUserToRole(string userLogin, string roleName)
        {
            //code in subclass
        }

        public virtual void RemoveUserFromRole(string userLogin, string roleName)
        {
            //code in subclass
        }

        public virtual void DeleteUser(string userName)
        {
            //code in subclass
        }

        protected bool CheckUserEmailUnique(string email)
        {
            var emails = _dbContext.Get<UserProfile>(x => x.Email == email);          
            return emails.Count() == 0 ? true : false; 
        }

        protected bool CheckUserExist(string userLogin)
        {
            return _dbContext.Get<UserProfile>(x => x.UserLogin == userLogin).Any();           
        }

        protected void SendConfirmationToken(string userEmail, string subject, string message)
        {
            _emailer.SendSingleEmail(userEmail, subject, message);
        }        
    }
}
